import { createRouter, createWebHashHistory, type RouteRecordRaw } from "vue-router";
import NProgress from "nprogress"; //进度条插件

// 关闭进度条加载圈
NProgress.configure({ showSpinner: false });
const routes: RouteRecordRaw[] = [
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/home",
    name: "home",
    component: () => import("@/views/home/index.vue"),
    meta: {
      title: "首页",
    },
  },
  {
    path: "/search",
    name: "search",
    component: () => import("@/views/search/index.vue"),
    meta: {
      title: "搜索",
    },
  },
  {
    path: "/message",
    name: "message",
    component: () => import("@/views/message/index.vue"),
    meta: {
      title: "留言",
    },
  },
  {
    path: "/site",
    name: "site",
    component: () => import("@/views/web/index.vue"),
    meta: {
      title: "站点",
    },
  },
  {
    path: "/about",
    name: "about",
    component: () => import("@/views/about/index.vue"),
    meta: {
      title: "关于",
    },
  },
  {
    path: "/article/:id",
    name: "article",
    component: () => import("@/views/article/index.vue"),
    meta: {
      title: "文章详情",
    },
  },

  {
    path: "/:pathMatch(.*)*",
    name: "notFound",
    component: () => import("@/views/notFound/index.vue"),
    meta: {
      title: "not Found",
    },
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

router.beforeEach((to, from) => {
  NProgress.start();
});
router.afterEach((to) => {
  document.title = `F's Blog | ${(to.meta.title as string) || ""}`;
  NProgress.done();
});

export default router;
